package org.dce.screencapturer.actions.objects;

import java.awt.Font;
import java.awt.font.TextAttribute;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.HashMap;
import java.util.Map;

import org.dce.screencapturer.util.IconFactory;

@SuppressWarnings("serial")
public class SetFontStrikeThroughAction 
	extends FontAction {


	public SetFontStrikeThroughAction() {
		super("actions.toggleStrikeThrough", IconFactory.getIcon("/images/format-text-strikethrough.png"));
	}

	@Override
	protected Font modifyFont(Font font) {
		
		boolean underline = TextAttribute.STRIKETHROUGH_ON.equals(font.getAttributes().get(TextAttribute.STRIKETHROUGH));

		Map<Attribute,Object> attributes = new HashMap<Attribute, Object>(font.getAttributes());

		if (underline){
			attributes.put(TextAttribute.STRIKETHROUGH, null);
		} else {
			attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
		}

		return font.deriveFont(attributes);
	}
}
